package com.example.reactor;

import reactor.core.publisher.Flux;

import java.time.Duration;
import java.util.concurrent.TimeUnit;

public class Practice10 {

    public static void main(String[] args) {

        Flux.range(1, 1000)
                .take(10)
                .subscribe(System.out::println);

        System.out.println("---------------------------------------分割线-------------------------------------");

        Flux.interval(Duration.ofMillis(10))
                .take(Duration.ofMillis(100))
                .subscribe(System.out::println);

        System.out.println("---------------------------------------分割线-------------------------------------");

        Flux.range(1, 1000)
                .takeLast(10)
                .subscribe(System.out::println);

        System.out.println("---------------------------------------分割线-------------------------------------");

        Flux.range(1, 1000)
                .takeWhile(i -> i < 20)
                .subscribe(System.out::println);

        System.out.println("---------------------------------------分割线-------------------------------------");

        Flux.range(1, 1000)
                .takeUntil(i -> i > 100)
                .subscribe(System.out::println);


        while (true) {
            try {
                TimeUnit.SECONDS.sleep(1L);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }

    }
}
